import React, { Component } from 'react';
import { getcar_list } from '../../api/index'
import { NavBar, Radio,Stepper } from 'antd-mobile';
import MyTop1 from '../../components/Rests/MyTop1'
import '../../styles/shopcar.css'
class ShopCar extends Component {
    constructor(props) {
        super(props);
        this.state = {
            carList: [],
        }
    }
    componentDidMount() {
        getcar_list({ userid: localStorage.getItem("userId") }).then(res => {
            console.log(res.data.list);
            this.setState({ carList: res.data.list })
        })
    }
    // 点击返回
    back() {
        this.props.history.go(-1)
    }
    // 点击+和-
    changeNum(value) {
        console.log(value);
    }
    render() {
        return (
            <div className='shopcar'>
                <NavBar onBack={() => { this.back() }}>购物车({this.state.carList.length})</NavBar>
                <MyTop1 />
                {
              
                    this.state.carList.map((item, index) => {
                        return (
                            <div className='carbox' key={index}>
                                <Radio />
                                <div className='carbox1'>
                                  <img src={item.pic} alt="" />
                                </div>
                                <div className='carbox2'>
                                    <span>{item.name}</span>
                                    <div className='carbox3'>
                                        <span>￥{item.salesPrice.value}</span>
                                        <Stepper
                                            defaultValue={1}
                                            onChange={(value)=>{this.changeNum(value)}}
                                        />
                                    </div>
                                </div>
                            </div>
                        )
                    })
                
                }
            </div>
        );
    }
}

export default ShopCar;